package com.isoft.demo01.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.isoft.demo01.entity.Shop;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface ShopDao extends BaseMapper<Shop> {

    int findCartQuantity(Integer userid);
    //查询指定用户编号指定商品编号的购物项 （添加购物车时使用）
    Shop findCart(@Param("userid") Integer userid, @Param("gameid") Integer gameid);

    //查询用户购物车列表
    @Select("select *,tb_game.gamename,tb_game.price,tb_game.photo from tb_shop inner join tb_game on tb_shop.gameid=tb_game.gameid where userid=#{userid}")
    List<Shop> findCartList(Integer userid);

    //批量删除
    int deleteCartBatch(List<Integer> id, Integer userid);

    //清空购物车
    int clearCart(Integer userid);

    //删除选中的商品
    @Delete("delete from tb_shop where id=#{id}")
    int deleteByid(@Param("id") Integer id);
    @Select("select tb_shop.id,tb_shop.userid,tb_shop.gameid,tb_game.gamename,tb_game.price,tb_game.photo from tb_game left join tb_shop on tb_shop.gameid=tb_game.gameid where id=#{id};")
    Shop selectById(Integer id);
    @Insert("insert into tb_shop (userid,gameid) values (#{userid},#{gameid})")
    int addcart(@Param("userid") Integer userid,@Param("gameid") Integer gameid);
    @Select("select sum(price) from tb_shop inner join tb_game on tb_shop.gameid=tb_game.gameid where userid=#{userid} ")
    int allprice(Integer userid);
}
